home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 November
/
EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso
/
earcd
/
program
/
gcc
/
gcc270-d.lha
/
gnu
/
man
/
cat3
/
qsort.0
< prev
next >
Wrap
Text File
|
1992-08-10
|
4KB
|
133 lines
QSORT(3) UNIX Programmer's Manual QSORT(3)
NNAAMMEE
qqssoorrtt,, hheeaappssoorrtt - sort functions
SSYYNNOOPPSSIISS
##iinncclluuddee <<ssttddlliibb..hh>>
_v_o_i_d
qqssoorrtt(_v_o_i_d _*_b_a_s_e, _s_i_z_e___t _n_m_e_m_b, _s_i_z_e___t _s_i_z_e,
_i_n_t _(_*_c_o_m_p_a_r_)_(_c_o_n_s_t _v_o_i_d _*_, _c_o_n_s_t _v_o_i_d _*_))
_i_n_t
hheeaappssoorrtt(_v_o_i_d _*_b_a_s_e, _s_i_z_e___t _n_m_e_m_b, _s_i_z_e___t _s_i_z_e,
_i_n_t _(_*_c_o_m_p_a_r_)_(_c_o_n_s_t _v_o_i_d _*_, _c_o_n_s_t _v_o_i_d _*_))
DDEESSCCRRIIPPTTIIOONN
The qqssoorrtt() function is a modified partitionexchange sort, or quicksort.
The hheeaappssoorrtt() function is a modified selection sort.
The qqssoorrtt() and hheeaappssoorrtt() functions sort an array of _n_m_e_m_b objects, the
initial member of which is pointed to by _b_a_s_e. The size of each object is
specified by _s_i_z_e.
The contents of the array are sorted in ascending order according to a
comparison function pointed to by _c_o_m_p_a_r, which is called with two argu
ments that point to the objects being compared.
The comparison function must return an integer less than, equal to, or
greater than zero if the first argument is considered to be respectively
less than, equal to, or greater than the second.
The functions qqssoorrtt() and hheeaappssoorrtt() are _n_o_t stable, that is, if two mem
bers compare as equal, their order in the sorted array is undefined.
The qqssoorrtt() function is an implementation of C.A.R. Hoare's ``quicksort''
algorithm, a variant of partitionexchange sorting; in particular, see
D.E. Knuth's Algorithm Q. QQssoorrtt() takes O N lg N average time. This im
plementation uses median selection to avoid the traditional O N**2 worst
case behavior.
The hheeaappssoorrtt() function is an implementation of J.W.J. William's ``heap
sort'' algorithm, a variant of selection sorting; in particular, see D.E.
Knuth's Algorithm H. HHeeaappssoorrtt() takes O N lg N worstcase time. Its
_o_n_l_y advantage over qqssoorrtt() is that it uses no additional memory.
RREETTUURRNN VVAALLUUEESS
The qqssoorrtt() function returns no value.
Upon successful completion, hheeaappssoorrtt() returns 0. Otherwise, it returns
-1 and the global variable _e_r_r_n_o is set to indicate the error.
EERRRROORRSS
The hheeaappssoorrtt() function succeeds unless:
[EINVAL] The _s_i_z_e argument is zero.
CCOOMMPPAATTIIBBIILLIITTYY
Previous versions of qqssoorrtt() did not permit the comparison routine to it
self call qqssoorrtt(_3). This is no longer true.
SSEEEE AALLSSOO
sort(1), radixsort(3)
Hoare, C.A.R., "Quicksort", _T_h_e _C_o_m_p_u_t_e_r _J_o_u_r_n_a_l, 5:1, pp. 1015, 1962.
Williams, J.W.J, "Heapsort", _C_o_m_m_u_n_i_c_a_t_i_o_n_s _o_f _t_h_e _A_C_M, 7:1, pp. 347348,
1964.
Knuth, D.E., "Sorting and Searching", _T_h_e _A_r_t _o_f _C_o_m_p_u_t_e_r _P_r_o_g_r_a_m_m_i_n_g,
Vol. 3, pp. 114123, 145149, 1968.
SSTTAANNDDAARRDDSS
The qqssoorrtt() function conforms to ANSI C3.1591989 (``ANSI C'').
BSD Experimental June 29, 1991 2